<!DOCTYPE html>
<html>
	<head>
		  <meta charset="utf-8">
		  <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		  <title></title>
		  <link href="../../static/mui/css/mui.min.css" rel="stylesheet"/>
		  <style>
		    #againCodeButton {
			    position: absolute;
			    top: 1px;
			    left: 54%;
			}
			.mui-input-row .mui-btn {
			    width: 45%;
			}
			.mui-btn-block {
		   	    padding: 9px 0;
			}
		 </style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav" style="background-color:#dd524d;">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #fff;"></a>
		    <h1 class="mui-title" style="color: #fff;">密码重置</h1>
		</header>
		<div class="mui-content" style="margin-top:20px;">
		    <form class="mui-input-group">
		        <div class="mui-input-row">
		            <input type="text" id="verifyCode" class="mui-input-clear" placeholder="验证码" maxlength="4"> 
		            <button type="button" id="againCodeButton"  class="mui-btn mui-btn-primary mui-icon" disabled="disabled">
		            	60秒后重新获取
		        	</button>
		        </div>
		         <div class="mui-input-row">
		            <input type="password" id="pwd" class="mui-input-clear" placeholder="密码">
		        </div>
		         <div class="mui-input-row">
		            <input type="password" id="confirmPwd" class="mui-input-clear" placeholder="确认密码">
		        </div>
		    </form>
		    <div class="mui-content-padded">
				<button id="doResetPwdBtn" type="button" class="mui-btn mui-btn-block mui-btn-primary">提交</button>
			</div>
		</div>
		<script src="../../static/mui/js/mui.min.js" type="text/javascript"></script>
	    <script src="../../static/lib/jquery-1.11.2.min.js" type="text/javascript"></script>
	    <script src="../../static/app/js/kit.js" type="text/javascript"></script>
	    <script src="../../static/app/js/api.js" type="text/javascript"></script>
	    <script type="text/javascript">
	    mui.plusReady(function(){
	    	var countdown=60;
			var inteval = null;
	    	var self = plus.webview.currentWebview();
			var phone = self.phone;
			if(!phone){
	    		Kit.ui.alert("验证的手机号为空");
	    		return;
		    }else{
			    //页面首次进来进行倒计时
			    takeTime();
		    }
		    function takeTime(){
			   inteval= setInterval(function(){ 
					    	if(countdown == 0){
								$("#againCodeButton").removeAttr("disabled");
								$("#againCodeButton").html("点击获得验证码");
								clearInterval(inteval);
							    countdown=60;
					    	}else if(countdown > 0){
					    		$("#againCodeButton").attr({"disabled":"disabled"});
						    	$("#againCodeButton").html(countdown+"秒后重新获得");
						    	countdown--;
					    	}
					
					},1000);
			}
		    document.getElementById("againCodeButton").addEventListener("tap",function(){
		     	clearInterval(inteval);
		  		takeTime();
		  		if(!phone){
		    		Kit.ui.alert("验证的手机号为空");
		    		return;
		    	}else{
		    		API.sendResetPwdCode(phone);
		    	}
		    });
		   document.getElementById("doResetPwdBtn").addEventListener("tap",function(){
		   		var showMask = Kit.ui.showLoading();
		    	if(!phone){
		    		showMask.close();
		    		Kit.ui.alert("验证的手机号为空");
		    		return;
		    	}
		    	var verifyCode = $("#verifyCode").val();
		    	if(!verifyCode){
		    		showMask.close();
		    		Kit.ui.alert("验证码为空");
		    		return;
		    	}
		    	var pwd = $("#pwd").val();
		    	if(!pwd){
		    		showMask.close();
		    		Kit.ui.alert("确认密码为空");
		    		return;
		    	}else if(pwd.length>18){
		    		showMask.close();
		    		Kit.ui.alert("密码长度不能大于18位");
		    		return;
		    	}else if(pwd.length<6){
		    		showMask.close();
		    		Kit.ui.alert("密码长度不能小于6位");
		    		return;
		    	}
		    	var confirmPwd = $("#confirmPwd").val();
		    	if(!confirmPwd){
		    		showMask.close();
		    		Kit.ui.alert("确认密码为空");
		    		return;
		    	}else if(confirmPwd.length>18){
		    		showMask.close();
		    		Kit.ui.alert("确认密码长度不能大于18位");
		    		return;
		    	}else if(confirmPwd.length<6){
		    		showMask.close();
		    		Kit.ui.alert("确认密码长度不能小于6位");
		    		return;
		    	}else if(confirmPwd!=pwd){
		    		showMask.close();
		    		Kit.ui.alert("两次密码不一致");  
		    		return;
		    	}
		    	API.resetPwd(phone,verifyCode,pwd,confirmPwd, 
		    		function(){
			    		showMask.close();
			    		//应用重新启动
						plus.runtime.restart();
			    		/*mui.openWindow({
							url:'../login.html'
							});*/
					},function(){
						showMask.close();
					});
		    	});
	    });
	    </script>
	</body>
</html>
